import sys
from PySide6.QtWidgets import *
from PySide6.QtCore import *
 
class TableModel(QAbstractItemModel):
    def __init__(self, data, parent=None):
        super().__init__(parent)
        self._data = data
 
    def rowCount(self, parent: QModelIndex = ...) -> int:
        return len(self._data)
 
    def columnCount(self, parent: QModelIndex = ...) -> int:
        return len(self._data[0]) if self._data else 0
 
    def data(self, index: QModelIndex, role: int = ...):
        if not index.isValid() or role != Qt.DisplayRole:
            return None
        return self._data[index.row()][index.column()]
 
    def index(self, row: int, column: int, parent: QModelIndex = ...) -> QModelIndex:
        if not self.hasIndex(row, column, parent):
            return QModelIndex()
        return self.createIndex(row, column, None)
 
    def parent(self, index: QModelIndex) -> QModelIndex:
        return QModelIndex()
 
 
def main():
    app = QApplication(sys.argv)
    data = [
        ['Name', 'Age', 'Country'],
        ['Alice', 23, 'USA'],
        ['Bob', 28, 'UK'],
        ['Charlie', 35, 'Canada']
    ]
    model = TableModel(data)
 
    tableView = QTableView()
    tableView.setModel(model)
 
    window = QWidget()
    layout = QVBoxLayout()
    layout.addWidget(tableView)
    window.setLayout(layout)
    window.show()
 
    sys.exit(app.exec())
 
 
if __name__ == '__main__':
    main()